﻿<div style="width:600px;margin:0 auto;padding-top:20px;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">路由标识</label>
            <div class="layui-input-block">
                <input type="text" name="routeId" win-verify="required" placeholder="请输入路由标识" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">URI</label>
            <div class="layui-input-block">
                <input type="text" name="routeUri" win-verify="required" placeholder="请输入URI" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="routeOrder" value="0" win-verify="number" placeholder="请输入排序值" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Predicates</label>
            <div class="layui-input-block">
                <textarea name="predicates" class="layui-textarea" placeholder="示例：[{'name':'Path','args':{'pattern':'/baidu'}}]"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Filters</label>
            <div class="layui-input-block">
                <textarea name="filters" class="layui-textarea" placeholder="示例：[{'name':'StripPrefix','args':{'_genkey_0':'1'}}]"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="winui-btn" lay-submit lay-filter="formAddMenu">确定</button>
                <button class="winui-btn" onclick="winui.window.close('addMenu'); return false;">取消</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function (form) {
        var $ = layui.$
            , msg = winui.window.msg;
        form.render();
        form.on('submit(formAddMenu)', function (data) {
            //表单验证
            if (winui.verifyForm(data.elem)) {
                layui.$.ajax({
                    type: 'post',
                    url: '/gateway/add',
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    success: function (json) {
                        if (json.success) {
                            msg('添加成功');
                        } else {
                            msg(json.message)
                        }
                        winui.window.close('addMenu');
                    },
                    error: function (xml) {
                        msg('添加失败');
                        console.log(xml.responseText);
                    }
                });
            }
            return false;
        });
    });
</script>